<template>
  <div>
      <!-- 树形控件 -->
        <el-tree
            :props="props"
            :load="loadNode"
            @node-click='getName'
            lazy
        >
        </el-tree>
  </div>
</template>

<script>
export default {
    name:'productTree',
    data(){
        return{
            props: {
                label: 'name',
                children: '',
            },
        }
    },
    methods:{
        //获取树形结构点击数据
        getName(data){
            console.log(data)
            this.$emit('getleimu',data)
        },
        //树形结构数据展示
        loadNode(node, resolve) {
            console.log(node)
        if (node.level === 0) {
            console.log(this)
            this.$api.getSelectCategory(1)
            .then(data=>{
                console.log(data)
                return resolve(data.data)
            })
        }else{
            this.$api.getSelectCategory(node.data.cid)
            .then(data=>{
                console.log(data)
                return resolve(data.data)
            })
            .catch(error=>{ //eslint-disable-line
                return resolve([])
            })
        }

        
      }
    }
}
</script>

<style>

</style>